﻿<%@ Page Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false" CodeFile="recCorporateActionlist.aspx.cs"
    Inherits="SIPO.Web.Lists.Transaction.recCorporateActionlist" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <div>
        <button id="btnAdd" type="button" onclick="OpenForm('add');">
            Tambah</button>
        <button id="btnEdit" type="button" onclick="OpenForm('edit');">
            Ubah</button>
        <button id="btnDelete" type="button" onclick="OpenForm('delete');">
            Hapus</button>
    </div>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog1" title="Default dialog">
    </div>
    <script type="text/javascript">

        $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
        $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
        $("#btnDelete").button({ icons: { primary: "ui-icon-trash"} });

    </script>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recCorporateActionhandler.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ID', 'Jenis Usaha', 'Nama Perusahaan', 'Nama Emiten Aksi', 'Nilai Emisi (Rp)', 'Tagihan (Rp)', 'No Invoice', 'No Payment'],
            colModel: [
           		{ name: 'CorporateActionID', key: true, hidden: true, index: 'CorporateActionID', width: 5 },
           		{ name: 'recSubSubSector.SubSubSectorName', index: 'ISNULL(recSubSubSector.SubSubSectorName, recCorporateAction.CorporateSector)', width: 200, align: 'center', searchoptions: { sopt: ['eq', 'cn']} },
                { name: 'CorporateName', index: 'CorporateName', width: 200, align: 'center', searchoptions: { sopt: ['eq', 'cn']} },
                { name: 'recDebtor.DebtorName', index: 'Debtor.DebtorName', width: 200, align: 'center', searchoptions: { sopt: ['eq', 'cn']} },
                { name: 'ImpositionValue', index: 'recCorporateAction.ImpositionValue', width: 100, formatter: 'currency', searchtype: 'number', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                { name: 'recBilling.Value', index: 'recBilling.Value', width: 100, formatter: 'currency', searchtype: 'number', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                { name: 'InvoiceNo', index: 'recCorporateAction.InvoiceNo', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                { name: 'PaymentNo', index: 'recCorporateAction.PaymentNo', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
           	],
            rowNum: 10,
            id: 'CorporateActionID',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'CorporateActionID',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            height: '100%',
            caption: 'Aksi Korporasi',
            ajaxGridOptions: { cache: false }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true, showQuery: false });

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/transaction/recCorporateActionform.aspx") %>';

            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'CorporateActionID'));
            });
            if (ctl == 'edit') {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di edit!');
                else {
                    if (selIds.length > 1) {
                        alert('Pilih satu record untuk ubah data!');
                    }
                    else if (selIds.length == 1) {
                        $('#dialog1').load(formUrl + '?id=' + selText).dialog({ autoOpen: false, modal: true, width: 1000, title: 'Ubah Aksi Korporasi' });
                        $("#dialog1").dialog('open');
                    }
                }
            }
            else if (ctl == 'add') {
                $('#dialog1').load(formUrl + '?isInternal=1').dialog({ autoOpen: false, modal: true, width: 1000, title: 'Tambah Aksi Korporasi' });
                $("#dialog1").dialog('open');
            }
            else if (ctl == 'delete') {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di hapus!');
                else {
                    var result = window.confirm('Apakah Anda yakin untuk menghapus data ini?');
                    if (result) {

                        var objrecRegistration = new Object();
                        objrecRegistration.RegistrationID = encodeURIComponent(selText);

                        jsonData = JSON.stringify(objrecRegistration);

                        CallAjax('<%= ResolveUrl("~/AjaxHandler/Transaction/recCorporateActionhandler.ashx") %>', "?method=delete", jsonData);

                        setTimeout("$('#table').trigger('reloadGrid');", 3000);
                    }
                }
            }
        }

    </script>
</asp:Content>
